const serve = require('koa-static')
const Koa = require('koa');//导入koa模块
const app = new Koa();//创建一个koa对象表现web应用本身
const {bodyParser} = require('@koa/bodyparser');//导入koa-body-parser模块
const Router = require('@koa/router');
const router = new Router()
const userRouter = require('./routers/user')
const jindianRouter = require('./routers/jingdian')
const mount = require('koa-mount');
const path = require('path');
const cors = require('@koa/cors');
const {Sequelize, DataTypes} = require('sequelize');


//托管静态资源文件夹
app.use(mount('/static',serve(path.join(__dirname,'./static'))))


//koa跨域配置
app.use(cors({
    origin(ctx){
        return '*';
    },
}))


router.get('/',(ctx,next)=>{
    ctx.body = {
        title:'hello koa',
        result:ctx.query
    }
});



 app.use(bodyParser())//使用bodyparser中间件，解析请求体
console.log(path.join(__dirname,'./static'))

 router.use(userRouter.routes())//注册用户路径
 router.use(jindianRouter.routes())//注册景点路径
 app.use(router.routes())//注册主路由
 app.use(router.allowedMethods())//允许使用所有的http方法




app.listen(3000);//服务器监听在3000端口
console.log('serve is running at http://localhost:3000')


